<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>首页</title>
    <link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <div class="title">
        <h2>数据表格</h2>
    </div>
    <div class="container">
        <table class="table">
            <tr>
                <th>序号</th>
                <th>用户名</th>
                <th>密码</th>
                <th>创建时间</th>
                <th>电子邮件</th>
                <th>人生格言</th>
                <th>性别</th>
            </tr>

            <?php
                //造对象
                $db = new mysqli("localhost", "root", "", "xhm");
                mysqli_set_charset($db,'utf8');
                //判断是否出错
                !mysqli_connect_error() or die("连接失败！");
                $sql = "select userID,userName,password,createTime,email,motto, CASE WHEN sex = '1' THEN '男' WHEN sex = '0' THEN '女' ELSE '其他' END from user";
                $result = $db->query($sql);
               
                while($attr = $result->fetch_row()){
                    $pwd = md5($attr[2]);
                    echo "
                        <tr>
                            <td>{$attr[0]}</td>
                            <td>{$attr[1]}</td>
                            <td>{$pwd}</td>
                            <td>{$attr[3]}</td>
                            <td>{$attr[4]}</td>
                            <td>{$attr[5]}</td>
                            <td>{$attr[6]}</td>
                        </tr>
                    ";
                }
                $db->close();
            ?>
        </table>
    </div>
</body>
</html>